﻿using System.Text;

Solution solution = new Solution();
// add your code here for debugging

IList<string> GenerateParenthesis(int n)
{
    return Enumerable.Range(Enumerable.Range(0, n).Aggregate(0, (acc, i) => acc |= 1 << (2 * i + 1)),
              n == 0 ? 0 : (1 << 2 * n) - (1 << n) - Enumerable.Range(0, n).Aggregate(0, (acc, i) => acc |= 1 << (2 * i + 1)) + 1)
          .Where(num => Enumerable.Range(0, 2 * n).Aggregate(0, (last, i) => last < 0 ? last : last + ((num >> i & 1) == 0 ? 1 : -1), value => value == 0))
          .Select(num => Convert.ToString(num, 2).Replace('1', '(').Replace('0', ')')).ToList();
}

string ToString(IList<string> list)
{
    // new List<string>(2) { "(())", "()()" },
    StringBuilder stringBuilder = new StringBuilder().
        Append("new List<string>(").
        Append(list.Count).
        Append(") { ");
    foreach (var item in list)
    {
        _ = stringBuilder.Append('\"').
            Append(item).
            Append("\", ");
    }
    return stringBuilder.Remove(stringBuilder.Length - 2, 2).Append(" },").ToString();
}

StringBuilder stringBuilder = new StringBuilder();
for (int i = 1; i <= 8; i++)
{
    // 2 => X
    _ = stringBuilder.Append(i)
        .Append(" => ")
        .AppendLine(ToString(GenerateParenthesis(i)));
}
Console.WriteLine(stringBuilder.ToString());